﻿using System;
using System.CodeDom;
using System.Data;
using System.Linq;
using System.Text;
using BD.Standard.YCWH.ProgramParse.Forms;
using BD.Standard.YCWH.ProgramParse.Utils;

namespace BD.Standard.YCWH.ProgramParse
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string type = "stock";
            if (args.Any())
            {
                type = args[0];
                
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("入参类型:Base、Order、Stock");
                sb.AppendLine("     Base:获取物料，供应商数据");
                sb.AppendLine("     Order:获取采购订单数据");
                sb.AppendLine("     Stock:获取出入库");
                sb.Append("输入入参类型:");
                Console.Write(sb.ToString());
                type = Console.ReadLine();

            }

            DBConnection Con = new DBConnection();

            //获取机构
            var org = new Org();
            org.PostOrg(Con);

            DataSet orgIdsSet1 = null;


            switch (type.ToLower())
            {
                //获取基础资料
                case "base":
                    DataSet orgIdsSet = Con.getDataSet("select orgId,orgType,inStockType,outStockType from YCWH_org where orgType=1 or (orgType=5 and poiStatus=0)");

                    //物品档案
                    var material = new Material();
                    //material.PostMaterial(orgIdsSet);

                    //供应商档案
                    var supplier = new Supplier();
                    supplier.PostSupplier(orgIdsSet);


                   

                    break;

                case "order":


                    orgIdsSet1 = Con.getDataSet("select orgId,orgType,inStockType,outStockType from YCWH_org where orgType=4 or (orgType=5 and poiStatus=0)");

                    //采购订单表头
                    PurchaseOrder purchaseOrder = new PurchaseOrder();
                    purchaseOrder.PostPurchaseOrder(orgIdsSet1);


                    //采购订单明细
                    //查询当前时间的采购订单的单号，关联查询组织表YCWH_orgId，获取orgId的orgType，作为查询条件。根据orgId分组，得到Array类型的订单号
                    DataSet orgIdsSet2 = Con.getDataSet("select orgId,orgType,purchaseOrderSn from  [dbo].[YCWH_PurchaseOrder] p left join [dbo].[YCWH_Org] o on p.orgInfo_orgId=o.orgId");
                    PurchaseOrderEntry purchaseOrderEntry = new PurchaseOrderEntry();
                    purchaseOrderEntry.PostPurchaseOrderEntry(orgIdsSet2);
                    break;

                //获取出入库单据
                case "stock":

                    orgIdsSet1 = Con.getDataSet("select orgId,orgType,inStockType,outStockType from YCWH_org where orgType=4 or (orgType=5 and poiStatus=0)");

                    //入库单表头
                    InStock inStock = new InStock();
                    inStock.PostInStock(orgIdsSet1);

                    DataSet orgIdsSetIn = Con.getDataSet("select orgId,orgType,itemSn from  [dbo].[YCWH_InStock] p left join [dbo].[YCWH_Org] o on p.belongOrg_orgId=o.orgId");
                    InStockEntry inStockEntry = new InStockEntry();
                    inStockEntry.PostInStockEntry(orgIdsSetIn);

                    //出库单表头
                    OutStock outStock = new OutStock();
                    outStock.PostOutStock(orgIdsSet1);

                    DataSet orgIdsSetOut = Con.getDataSet("select orgId,orgType,itemSn from  [dbo].[YCWH_OutStock] p left join [dbo].[YCWH_Org] o on p.belongOrg_orgId=o.orgId");
                    OutStockEntry outStockEntry = new OutStockEntry();
                    outStockEntry.PostOutStockEntry(orgIdsSetOut);


                    break;

                case "token":

                    //后台授权参数
                    var accessToken = new access_token();
                    accessToken.gettoken();


                    break;

                default:

                    Console.WriteLine("入参类型不正确");

                    break;


            }

        }
    }

}
